#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<string.h>
#include<stdbool.h>
//栈的定义
typedef struct Node{
    char *Data;
    int MaxSize;  //容量
    int Top; //栈顶
}Node,*Stack;

Stack CreatStack(int Max)
{
    Stack S = (Stack)malloc(sizeof(Node));
    S->Data = (char *)malloc(Max * sizeof(char));
    S->MaxSize = Max;
    S->Top = -1;
    return S;
}

int IsFull(Stack S)
{
    return S->Top == S->MaxSize - 1;
}

void Push(char x, Stack S)
{
    if (IsFull(S))
        printf("stack is full");
    else
    {
        S->Top=S->Top+1;
        S->Data[S->Top]=x;
    }
}

int IsEmpty(Stack S)
{
    return S->Top == -1;
}

void Pop(Stack S)
{
    if (IsEmpty(S))
        printf("stack is empty");
    else
        S->Top--;
}
char Top(Stack S)
{
    if (IsEmpty(S))
        printf("stack is empty");
    else
        return S->Data[S->Top];
}
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);

    for(int i=0;i<n;i++){
        char c[101];
        scanf("%s",c);
        int l = strlen(c);
        Stack S = CreatStack(m);
        int k=0;

        for(int j=0;j<l;j++){
            if(c[j]=='S'){
                if(IsFull(S)){
                    k=1;
                    break;
                }  
                Push('a',S);      
            }
            else{
                if(IsEmpty(S)){
                    k=1;
                    break;
                }
                Pop(S);
            }
        }
        
        if(!IsEmpty(S))
            k=1;
        if(k==1)
            printf("NO\n");
        else
            printf("YES\n");
    }
    return 0;
}
//堆栈操作合法性 